import { App } from 'vue'
import { createRouter, createWebHistory } from "vue-router"
import { createRouterGuards } from './permission'
import { PageEnum } from '@/enums/pageEnum'
import Layout from '@/layout/index.vue'

const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    hidden: true,
    component: () => import('@/views/login/index.vue')
  }, {
    path: '/',
    name: 'root',
    component: Layout,
    redirect: PageEnum.BASE_HOME
  }, {
    path: '/about',
    name: 'about',
    redirect: '/about/index',
    component: Layout,
    meta: {
      title: '关于',
      icon: ''
    },
    children: [
      {
        path: 'index',
        name: '说明',
        meta: {
          title: '说明',
        },
        component: () => import('@/views/about/index.vue')
      }
    ]
  }, {
    path: '/icon',
    name: 'icon1',
    redirect: '/icon/index',
    component: Layout,
    meta: {
      
    },
    children: [
      {
        path: 'index',
        name: 'icon',
        meta: {
          keepAlive: true,
          title: '图标管理'
        },
        component: () => import('@/views/icon/index.vue')
      }
    ]
  }, {
    path: '/404',
    name: '404',
    hidden: true,
    component: () => import('@/views/error/404.vue')
  }, {
    path: '/redirect',
    name: 'Redirect',
    component: Layout,
    hidden: true,
    meta: {
      title: 'Redirect',
      hideBreadcrumb: true,
    },
    children: [
      {
        path: '/redirect/:path(.*)',
        name: 'Redirect1',
        component: () => import('@/views/redirect/index.vue'),
        meta: {
          title: 'Redirect1',
          hideBreadcrumb: true,
        }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  strict: true,
})

export function setupRouter(app: App) {
  app.use(router),
  // 创建路由权限
  createRouterGuards(router)
}

// 重置路由为默认
export function resetRouter() {
  console.log("router", router.getRoutes())
}

export { constantRoutes }

export default router

